package my.study.designpattern.templatemethod;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
 * 
 * @author fanhongjie
 *
 */
public class MyApplicationContext {
	private static  ApplicationContext context;
	
	private static void init() {
		System.out.println(MyApplicationContext.class.getClassLoader().getResource("my/study/designpattern/templatemethod/application-designpattern-templatemethod.xml").getFile());
		context = new ClassPathXmlApplicationContext("my/study/designpattern/templatemethod/application-designpattern-templatemethod.xml");
	}
	public static <T> T getBean(Class<T> cls, String beanName) {
		if (context == null) {
			synchronized (MyApplicationContext.class) {
				if (context == null) {
					init();
				}
			}
		}
		T bean = cls.cast(context.getBean(beanName));
		return bean;
	}
}
